home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / Multiprocessing 2.1v2 SDK / Sample Code / CPU meter ƒ / .c / Offscreen.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-23  |  30.5 KB  |  794 lines  |  [TEXT/CWIE]

  1. /***************************************************************************\
  2. |***************************************************************************|
  3. |                                                                            |
  4. |    File Name:    Offscreen.c                                                    |
  5. |                                                                            |
  6. |    Contains:    Implementation of _Offscreen GWorld buffers                    |
  7. |                                                                            |
  8. |    Written by:    GeoWar                                                        |
  9. |                                                                            |
  10. |    Copyright:    © 1995 by Apple Computer,Inc.,all rights reserved.            |
  11. |                                                                            |
  12. | **************************************************************************|
  13. |            C h a n g e        H i s t o r y (most recent first):                |
  14. | **************************************************************************|
  15. |        Vers      Date        Author        Description                            |
  16. |        ----    --------    ------    ----------------------------------------|
  17. |        2.14    05/03/00    GAW        Carbonized!                                |
  18. |        2.13    03/17/00    GAW        Changed code to actuall use pixelDepth! |
  19. |        2.12    12/15/99    GAW        Added Get/Set default NewGWorld flags    |
  20. |        2.11     6/16/99    GAW        GlobalToLocal when !gDefaultPixelDepth    |
  21. |        2.10     6/16/99    GAW        SetPort_offscreen now returns pixmap    |
  22. |        2.9         5/30/99    GAW        Bug fix - nil maskRgnHdl on open        |
  23. |        2.8        12/16/98    GAW        Added Get/Set Pixel Depth                |
  24. |        2.7        12/16/98    GAW        Added Get/Set Default CopyBit mask        |
  25. |        2.6         12/3/98    GAW        moved saved port/device info to struct    |
  26. |        2.5         9/25/98    GAW        Added more parameter validity checking    |
  27. |        2.4         9/25/98    GAW        Added Text Font/Size support            |
  28. |        2.3         9/25/98    GAW        Added Use count pixel locking/unlocking    |
  29. |        2.2         9/19/97    GAW        Added Get/Set Default Pixel Depth        |
  30. |        2.1         5/24/95    GAW        First public version                    |
  31. |        0.0         5/18/95    GAW        Initial version                            |
  32. |***************************************************************************|
  33. \***************************************************************************/
  34.  
  35. #pragma segment _Offscreen
  36.  
  37. /**\
  38. |**|    Includes
  39. \**/
  40.  
  41. #include <Memory.h>
  42. #include "Offscreen.h"
  43.  
  44. /**\
  45. |**|    Local (static) Globals
  46. \**/
  47.  
  48. static SInt16 gDefaultPixelDepth = 0;
  49. static GWorldFlags gDefaultGWorldFlags = 0;
  50.  
  51. /**\
  52. |**|    Local Function Prototypes
  53. \**/
  54.  
  55. /**\
  56. |**|    Global Functions
  57. \**/
  58.  
  59. /*
  60.   ##############################################################################
  61.   # Prototype:    Window_OffscreenPtr Open_Offscreen(WindowPtr pWindowPtr)
  62.   #=============================================================================
  63.   # Author:            GeoWar    Wednesday,May 24,1995
  64.   # Description:    Opens _Offscreen buffer & copies window to it.
  65.   # Parameters:        pWindowPtr - WindowPtr of the window we want to buffer.
  66.   # Returns:        Pointer to _Offscreen parameters
  67.   # Examples:        myWindow_OffscreenPtr = Open_Offscreen(myWindowPtr);
  68.   # Assumptions:    None 
  69.   # ****************************************************************************
  70.   #            C h a n g e        H i s t o r y (most recent first):
  71.   # ****************************************************************************
  72.   #        Vers      Date        Author        Description
  73.   #        ----    --------    ------    ------------------------------------------
  74.   #        2.14     5/03/00    GAW        Carbonized!
  75.   #        2.1         8/07/95    GAW        Changed to Open_OffscreenBuffer call.
  76.   #        0.0         5/24/95    GAW        Initial version
  77.   # ****************************************************************************
  78. */
  79. Window_OffscreenPtr Open_Offscreen(WindowPtr pWindowPtr)
  80. {
  81.     Window_OffscreenPtr the_Offscreen;
  82.     Rect globalRect;
  83.  
  84. #if TARGET_API_MAC_CARBON    // <2.14>
  85.     SetPortWindowPort(pWindowPtr);
  86.     GetWindowBounds(pWindowPtr,kWindowGlobalPortRgn,&globalRect);
  87. #else
  88.     SetPort((GrafPtr) pWindowPtr);
  89.     globalRect = pWindowPtr->portRect;
  90.     LocalToGlobal((Point *) &globalRect.top);
  91.     LocalToGlobal((Point *) &globalRect.bottom);
  92. #endif TARGET_API_MAC_CARBON
  93.  
  94.     the_Offscreen = Open_OffscreenBuffer(pWindowPtr, &globalRect);
  95.  
  96.     if (the_Offscreen)
  97.         Copy_Offscreen(the_Offscreen);
  98.  
  99.     return the_Offscreen;
  100. }
  101.  
  102. /*
  103.   ##############################################################################
  104.   # Prototype:
  105.   #        Window_OffscreenPtr Open_OffscreenBuffer(
  106.   #                WindowPtr pWindowPtr, const Rect* pRect)
  107.   #=============================================================================
  108.   # Author:            GeoWar    Wednesday,May 24,1995
  109.   # Description:    Opens _Offscreen buffer & copies window to it.
  110.   # Parameters:        pWindowPtr - WindowPtr of the window we want to buffer.
  111.   #                 pRect - (global) Rectangle of the area we want to buffer
  112.   # Returns:        Pointer to _Offscreen parameters
  113.   # Examples:        myWindow_OffscreenPtr = Open_OffscreenBuffer(myWindowPtr,&myRect);
  114.   # Assumptions:    None 
  115.   # ****************************************************************************
  116.   #            C h a n g e        H i s t o r y (most recent first):
  117.   # ****************************************************************************
  118.   #        Vers      Date        Author        Description
  119.   #        ----    --------    ------    ------------------------------------------
  120.   #        2.14     5/03/00    GAW        Carbonized!
  121.   #        2.13    03/17/00    GAW        Changed code to actuall use pixelDepth!
  122.   #        2.11     6/16/99    GAW        GlobalToLocal when (0 == gDefaultPixelDepth)
  123.   #        2.9         5/30/99    GAW        Bug fix - nil maskRgnHdl on open
  124.   #        2.6         12/3/98    GAW        moved saved port/device info to struct
  125.   #        2.4         9/25/98    GAW        Added Text Font/Size support
  126.   #        2.3         9/25/98    GAW        Added Use count pixel locking/unlocking
  127.   #        2.2         3/23/96    GAW        added myErr for error debugging
  128.   #        2.1         8/07/95    GAW        Initial version
  129.   # ****************************************************************************
  130. */
  131.  
  132. Window_OffscreenPtr Open_OffscreenBuffer(WindowPtr pWindowPtr,const Rect* pRect)
  133. {
  134.     Rect    tRect;
  135.     Window_OffscreenPtr the_Offscreen;
  136.     GWorldPtr theWorld;
  137.     OSErr myErr;
  138.  
  139.     if (pRect == nil)    // param error
  140.         return nil;
  141.  
  142.     tRect = *pRect;
  143.  
  144.     if (!(the_Offscreen = (Window_OffscreenPtr) NewPtr(sizeof(Window_Offscreen))))
  145.         return nil;
  146.  
  147. #if TARGET_API_MAC_CARBON    // <2.14>
  148.     SetPortWindowPort(pWindowPtr);
  149. #else
  150.     SetPort((GrafPtr) pWindowPtr);
  151. #endif TARGET_API_MAC_CARBON
  152.  
  153.     GetGWorld(&the_Offscreen->windowPort, &the_Offscreen->windowDevice);
  154.  
  155.     the_Offscreen->pixelDepth = gDefaultPixelDepth;    // <2.13>
  156.  
  157.     if (the_Offscreen->pixelDepth)
  158.         myErr = NewGWorld(&theWorld, the_Offscreen->pixelDepth,
  159.                     &tRect, 0L, the_Offscreen->windowDevice, 0);
  160.     else
  161.     {
  162.         GlobalToLocal((Point*) &tRect.top);    // <2.11>
  163.         GlobalToLocal((Point*) &tRect.bottom);    // <2.11>
  164.  
  165.         myErr = NewGWorld(&theWorld, 0,
  166.                     &tRect, 0L, the_Offscreen->windowDevice, noNewDevice);
  167.     }
  168.  
  169.     if (myErr == noErr)
  170.     {
  171.         the_Offscreen->offscreenWorld = theWorld;
  172.         the_Offscreen->offscreenDevice =
  173.             GetGWorldDevice(the_Offscreen->offscreenWorld);
  174.  
  175.         the_Offscreen->pixelslockedCount = 0;    // zero pixel lock use count
  176.         the_Offscreen->maskRgnHdl = nil;        // <2.7>
  177.  
  178.         if (SetPort_Offscreen(the_Offscreen) == nil)    // if we can't lock it...
  179.         {
  180.             DisposeGWorld(theWorld);
  181.             DisposePtr((Ptr)the_Offscreen);
  182.             return nil;
  183.         }
  184.  
  185.         SetOrigin(tRect.left, tRect.top);
  186. #if !OPAQUE_TOOLBOX_STRUCTS    // <2.14>
  187.         TextFont(pWindowPtr->txFont);
  188.         TextSize(pWindowPtr->txSize);
  189. #endif !OPAQUE_TOOLBOX_STRUCTS
  190.  
  191.         EraseRect(&tRect);
  192.         Restore_Port(the_Offscreen);
  193.         return (the_Offscreen);
  194.     }
  195.     else
  196.     {
  197.         DisposePtr((Ptr)the_Offscreen);
  198.         return nil;
  199.     }
  200. }
  201.  
  202. /*
  203.   ##############################################################################
  204.   # Prototype:    void Copy_Offscreen(Window_OffscreenPtr pWindow_OffscreenPtr)
  205.   #=============================================================================
  206.   # Author:            GeoWar    Wednesday,May 24,1995
  207.   # Description:    copies window to _Offscreen buffer.
  208.   # Parameters:        pWindow_OffscreenPtr - Pointer to _Offscreen parameters
  209.   # Returns:        none
  210.   # Examples:        Copy_Offscreen(myWindow_OffscreenPtr);
  211.   # Assumptions:    None
  212.   # ****************************************************************************
  213.   #            C h a n g e        H i s t o r y (most recent first):
  214.   # ****************************************************************************
  215.   #        Vers      Date        Author        Description
  216.   #        ----    --------    ------    ------------------------------------------
  217.   #        2.14     5/03/00    GAW        Carbonized!
  218.   #        2.5         9/25/98    GAW        Added parameter validity checking
  219.   #        2.1         8/07/95    GAW        Changed to Copy_OffscreenBuffer call.
  220.   #        0.0         5/24/95    GAW        Initial version
  221.   # ****************************************************************************
  222. */
  223. void Copy_Offscreen(Window_OffscreenPtr pWindow_OffscreenPtr)
  224. {
  225.     if (pWindow_OffscreenPtr)
  226.     {
  227.         Rect srcRect,dstRect;    // <2.14>
  228.  
  229. #if TARGET_API_MAC_CARBON    // <2.14>
  230.         GetPortBounds(pWindow_OffscreenPtr->windowPort,&srcRect);
  231.         GetPortBounds(pWindow_OffscreenPtr->offscreenWorld,&dstRect);
  232. #else
  233.         srcRect = pWindow_OffscreenPtr->windowPort->portRect;
  234.         dstRect = pWindow_OffscreenPtr->offscreenWorld->portRect;
  235. #endif TARGET_API_MAC_CARBON
  236.  
  237.         Copy_OffscreenBuffer(pWindow_OffscreenPtr,&srcRect,&dstRect);
  238.     }
  239. }
  240.  
  241. /*
  242.   ##############################################################################
  243.   # Prototype:
  244.   #        void Copy_OffscreenBuffer(
  245.   #            Window_OffscreenPtr pWindow_OffscreenPtr
  246.   #            const Rect* sRect, const Rect* dRect)
  247.   #=============================================================================
  248.   # Author:            GeoWar    Wednesday,May 24,1995
  249.   # Description:    copies window to _Offscreen buffer.
  250.   # Parameters:        pWindow_OffscreenPtr - Pointer to _Offscreen parameters
  251.   #                 sRect - Source Rectangle (onscreen)
  252.   #                    dRect - Destination Rectangle (offscreen)
  253.   # Returns:        none
  254.   # Examples:        Copy_Offscreen(myWindow_OffscreenPtr);
  255.   # Assumptions:    None
  256.   # ****************************************************************************
  257.   #            C h a n g e        H i s t o r y (most recent first):
  258.   # ****************************************************************************
  259.   #        Vers      Date        Author        Description
  260.   #        ----    --------    ------    ------------------------------------------
  261.   #        2.14     5/03/00    GAW        Carbonized!
  262.   #        2.7         12/16/98    GAW        Added Get/Set Default CopyBit mask
  263.   #        2.6         12/3/98    GAW        moved saved port/device info to struct
  264.   #        2.1         8/07/95    GAW        Initial version
  265.   # ****************************************************************************
  266. */
  267. void Copy_OffscreenBuffer(Window_OffscreenPtr pWindow_OffscreenPtr,
  268.                           const Rect* sRect,
  269.                           const Rect* dRect)
  270. {
  271.     PixMapHandle offScreenPixMapH;
  272.  
  273.     if (pWindow_OffscreenPtr)
  274.     {
  275.         offScreenPixMapH = SetPort_Offscreen(pWindow_OffscreenPtr);
  276.         if (offScreenPixMapH)
  277.         {
  278.             ForeColor(blackColor);                // Set the fore color to Black
  279.             BackColor(whiteColor);                // Set the back color to White
  280. #if TARGET_API_MAC_CARBON    // <2.14>
  281.             CopyBits(    GetPortBitMapForCopyBits(pWindow_OffscreenPtr->windowPort),    // <2.14>
  282.                         (BitMap *) *offScreenPixMapH, sRect, dRect, srcCopy,
  283.                         pWindow_OffscreenPtr->maskRgnHdl);
  284. #else
  285.             CopyBits(    (BitMap*) *pWindow_OffscreenPtr->windowPort->portPixMap,
  286.                         (BitMap*) *offScreenPixMapH, sRect, dRect, srcCopy,
  287.                         pWindow_OffscreenPtr->maskRgnHdl);
  288. #endif TARGET_API_MAC_CARBON
  289.             Unlock_Offscreen(pWindow_OffscreenPtr);
  290.         }
  291.         Restore_Port(pWindow_OffscreenPtr);
  292.     }
  293. }
  294.  
  295. /*
  296.   ##############################################################################
  297.   # Prototype:    void Copy_Onscreen(Window_OffscreenPtr pWindow_OffscreenPtr)
  298.   #=============================================================================
  299.   # Author:            GeoWar    Wednesday,May 24,1995
  300.   # Description:    copies _Offscreen buffer to screen.
  301.   # Parameters:        pWindow_OffscreenPtr - Pointer to _Offscreen parameters
  302.   # Returns:        none
  303.   # Examples:        Copy_Onscreen(myWindow_OffscreenPtr);
  304.   # Assumptions:    None
  305.   # ****************************************************************************
  306.   #            C h a n g e        H i s t o r y (most recent first):
  307.   # ****************************************************************************
  308.   #        Vers      Date        Author        Description
  309.   #        ----    --------    ------    ------------------------------------------
  310.   #        2.14     5/03/00    GAW        Carbonized!
  311.   #        2.5         9/25/98    GAW        Added parameter validity checking
  312.   #        2.1         8/07/95    GAW        Changed to Copy_OnscreenBuffer call.
  313.   #        0.0         5/24/95    GAW        Initial version
  314.   # ****************************************************************************
  315. */
  316. void Copy_Onscreen(Window_OffscreenPtr pWindow_OffscreenPtr)
  317. {
  318.     if (pWindow_OffscreenPtr)
  319.     {
  320.         Rect srcRect,dstRect;
  321. #if TARGET_API_MAC_CARBON    // <2.14>
  322.         GetPortBounds(pWindow_OffscreenPtr->offscreenWorld,&srcRect);
  323.         GetPortBounds(pWindow_OffscreenPtr->windowPort,&dstRect);
  324. #else
  325.         srcRect = pWindow_OffscreenPtr->offscreenWorld->portRect;
  326.         dstRect = pWindow_OffscreenPtr->windowPort->portRect;
  327. #endif TARGET_API_MAC_CARBON
  328.  
  329.         Copy_OnscreenBuffer(pWindow_OffscreenPtr,&srcRect,&dstRect);
  330.     }
  331. }
  332.  
  333. /*
  334.   ##############################################################################
  335.   # Prototype:
  336.   #        void Copy_OnscreenBuffer(
  337.   #            Window_OffscreenPtr pWindow_OffscreenPtr
  338.   #            const Rect* sRect,const Rect* dRect)
  339.   #=============================================================================
  340.   # Author:            GeoWar    Wednesday,May 24,1995
  341.   # Description:    copies _Offscreen buffer to screen.
  342.   # Parameters:        pWindow_OffscreenPtr - Pointer to _Offscreen parameters
  343.   #                 sRect - Source Rectangle (offscreen)
  344.   #                 dRect - Destination Rectangle (onscreen)
  345.   # Returns:        none
  346.   # Examples:        Copy_Onscreen(myWindow_OffscreenPtr);
  347.   # Assumptions:    None
  348.   # ****************************************************************************
  349.   #            C h a n g e        H i s t o r y (most recent first):
  350.   # ****************************************************************************
  351.   #        Vers      Date        Author        Description
  352.   #        ----    --------    ------    ------------------------------------------
  353.   #        2.7         12/16/98    GAW        Added Get/Set Default CopyBit mask
  354.   #        2.6         12/3/98    GAW        moved saved port/device info to struct
  355.   #        2.1         8/07/95    GAW        Initial version
  356.   # ****************************************************************************
  357. */
  358.  
  359. void Copy_OnscreenBuffer(Window_OffscreenPtr pWindow_OffscreenPtr,
  360.                          const Rect* sRect,
  361.                          const Rect* dRect)
  362. {
  363.     PixMapHandle offScreenPixMapH;
  364.     PixMapHandle onScreenPixMapH;
  365.  
  366.     if (pWindow_OffscreenPtr)
  367.     {
  368.         SetPort_Onscreen(pWindow_OffscreenPtr);
  369.         offScreenPixMapH = Lock_Offscreen(pWindow_OffscreenPtr);
  370. #if ACCESSOR_CALLS_ARE_FUNCTIONS    // <2.14>
  371.         onScreenPixMapH = GetPortPixMap(pWindow_OffscreenPtr->windowPort);
  372. #else
  373.         onScreenPixMapH = pWindow_OffscreenPtr->windowPort->portPixMap;
  374. #endif
  375.  
  376.         if (offScreenPixMapH && onScreenPixMapH)
  377.         {
  378.             Rect pixRect = (*offScreenPixMapH)->bounds;
  379.             Rect tRect = *sRect;
  380.  
  381.             OffsetRect(&tRect,pixRect.left,pixRect.top);
  382.  
  383.             ForeColor(blackColor);                // Set the fore color to Black
  384.             BackColor(whiteColor);                // Set the back color to White
  385. #if 1
  386.             if (GETPIXMAPPIXELFORMAT(*onScreenPixMapH) == GETPIXMAPPIXELFORMAT(*offScreenPixMapH))
  387. #else
  388.             if (    (*offScreenPixMapH)->pixelType == 
  389.                     (*(pWindow_OffscreenPtr->windowPort->portPixMap))->pixelType)
  390. #endif 1
  391.             {
  392.                 long seed = (*(*onScreenPixMapH)->pmTable)->ctSeed;
  393.                 (*((*offScreenPixMapH)->pmTable))->ctSeed = seed;
  394.             }
  395.  
  396.             CopyBits((BitMap *) *offScreenPixMapH,
  397.                     (BitMap *) *onScreenPixMapH,
  398.                     &tRect, dRect, srcCopy, pWindow_OffscreenPtr->maskRgnHdl);
  399.             Unlock_Offscreen(pWindow_OffscreenPtr);
  400.         }
  401.         Restore_Port(pWindow_OffscreenPtr);
  402.     }
  403. }
  404.  
  405. /*
  406.   ##############################################################################
  407.   # Prototype:    void Save_Port(void)
  408.   #=============================================================================
  409.   # Author:            GeoWar    Wednesday,May 24,1995
  410.   # Description:    save current CGrafPtr & GDHandle to _Offscreen globals.
  411.   # Parameters:        none
  412.   # Returns:        none
  413.   # Examples:        Save_Port();
  414.   # Assumptions:    None
  415.   # ****************************************************************************
  416.   #            C h a n g e        H i s t o r y (most recent first):
  417.   # ****************************************************************************
  418.   #        Vers      Date        Author        Description
  419.   #        ----    --------    ------    ------------------------------------------
  420.   #        2.6         12/3/98    GAW        moved saved port/device info to struct
  421.   #        0.0         5/24/95    GAW        Initial version
  422.   # ****************************************************************************
  423. */
  424. void Save_Port(Window_OffscreenPtr pWindow_OffscreenPtr)
  425. {
  426.     if (pWindow_OffscreenPtr)
  427.         GetGWorld(
  428.             &pWindow_OffscreenPtr->savedCGrafPtr,
  429.             &pWindow_OffscreenPtr->savedGDHandle);
  430. }
  431.  
  432. /*
  433.   ##############################################################################
  434.   # Prototype:    void Restore_Port(void)
  435.   #=============================================================================
  436.   # Author:            GeoWar    Wednesday,May 24,1995
  437.   # Description:    restore CGrafPtr & GDHandle from _Offscreen globals
  438.   # Parameters:        none
  439.   # Returns:        none
  440.   # Examples:        Restore_Port();
  441.   # Assumptions:    None
  442.   # ****************************************************************************
  443.   #            C h a n g e        H i s t o r y (most recent first):
  444.   # ****************************************************************************
  445.   #        Vers      Date        Author        Description
  446.   #        ----    --------    ------    ------------------------------------------
  447.   #        2.6         12/3/98    GAW        moved saved port/device info to struct
  448.   #        0.0         5/24/95    GAW        Initial version
  449.   # ****************************************************************************
  450. */
  451. void Restore_Port(Window_OffscreenPtr pWindow_OffscreenPtr)
  452. {
  453.     if (pWindow_OffscreenPtr && pWindow_OffscreenPtr->savedCGrafPtr)
  454.         SetGWorld(
  455.             pWindow_OffscreenPtr->savedCGrafPtr,
  456.             pWindow_OffscreenPtr->savedGDHandle);
  457. }
  458.  
  459. /*
  460.   ##############################################################################
  461.   # Prototype:    void Close_Offscreen(Window_OffscreenPtr pWindow_OffscreenPtr)
  462.   #=============================================================================
  463.   # Author:            GeoWar    Wednesday,May 24,1995
  464.   # Description:    Closes _Offscreen buffer
  465.   # Parameters:        pWindow_OffscreenPtr - Pointer to _Offscreen parameters
  466.   # Returns:        none
  467.   # Examples:        Close_Offscreen(myWindow_OffscreenPtr);
  468.   # Assumptions:    None
  469.   # ****************************************************************************
  470.   #            C h a n g e        H i s t o r y (most recent first):
  471.   # ****************************************************************************
  472.   #        Vers      Date        Author        Description
  473.   #        ----    --------    ------    ------------------------------------------
  474.   #        2.5         9/25/98    GAW        Added parameter validity checking
  475.   #        0.0         5/24/95    GAW        Initial version
  476.   # ****************************************************************************
  477. */
  478. void Close_Offscreen(Window_OffscreenPtr pWindow_OffscreenPtr)
  479. {
  480.     if (pWindow_OffscreenPtr)
  481.     {
  482.         if (pWindow_OffscreenPtr->offscreenWorld)
  483.             DisposeGWorld(pWindow_OffscreenPtr->offscreenWorld);
  484.         if (pWindow_OffscreenPtr)
  485.             DisposePtr((Ptr)pWindow_OffscreenPtr);
  486.         //    pWindow_OffscreenPtr = nil;
  487.     }
  488. }
  489.  
  490. /*
  491.   ##############################################################################
  492.   # Prototype:    void SetPort_Onscreen(Window_OffscreenPtr pWindow_OffscreenPtr)
  493.   #=============================================================================
  494.   # Author:            GeoWar    Wednesday,May 24,1995
  495.   # Description:    Set port & device to _Onscreen after saving current values
  496.   # Parameters:        pWindow_OffscreenPtr - Pointer to _Offscreen parameters
  497.   # Returns:        none
  498.   # Examples:        SetPort_Onscreen(myWindow_OffscreenPtr);
  499.   # Assumptions:    None
  500.   # ****************************************************************************
  501.   #            C h a n g e        H i s t o r y (most recent first):
  502.   # ****************************************************************************
  503.   #        Vers      Date        Author        Description
  504.   #        ----    --------    ------    ------------------------------------------
  505.   #        2.6         12/3/98    GAW        moved saved port/device info to struct
  506.   #        0.0         5/24/95    GAW        Initial version
  507.   # ****************************************************************************
  508. */
  509. void SetPort_Onscreen(Window_OffscreenPtr pWindow_OffscreenPtr)
  510. {
  511.     if (pWindow_OffscreenPtr)
  512.     {
  513.         Save_Port(pWindow_OffscreenPtr);
  514.         SetGWorld(pWindow_OffscreenPtr->windowPort,
  515.                     pWindow_OffscreenPtr->windowDevice);
  516.         SetPort((GrafPtr) pWindow_OffscreenPtr->windowPort);
  517.     }
  518. }
  519.  
  520. /*
  521.   ##############################################################################
  522.   # Prototype:    void SetPort_Offscreen(Window_OffscreenPtr pWindow_OffscreenPtr)
  523.   #=============================================================================
  524.   # Author:            GeoWar    Wednesday,May 24,1995
  525.   # Description:    Set port & device to _Offscreen after saving current values
  526.   # Parameters:        pWindow_OffscreenPtr - Pointer to _Offscreen parameters
  527.   # Returns:        none
  528.   # Examples:        Copy_Offscreen(myWindow_OffscreenPtr);
  529.   # Assumptions:    None
  530.   # ****************************************************************************
  531.   #            C h a n g e        H i s t o r y (most recent first):
  532.   # ****************************************************************************
  533.   #        Vers      Date        Author        Description
  534.   #        ----    --------    ------    ------------------------------------------
  535.   #        2.10     6/16/99    GAW        SetPort_offscreen now returns pixmap
  536.   #        2.6         12/3/98    GAW        moved saved port/device info to struct
  537.   #        0.0         5/24/95    GAW        Initial version
  538.   # ****************************************************************************
  539. */
  540. PixMapHandle SetPort_Offscreen(Window_OffscreenPtr pWindow_OffscreenPtr)
  541. {
  542.     if (pWindow_OffscreenPtr)
  543.     {
  544.         Save_Port(pWindow_OffscreenPtr);
  545.         SetGWorld(pWindow_OffscreenPtr->offscreenWorld,
  546.             pWindow_OffscreenPtr->offscreenDevice);
  547.         return Lock_Offscreen(pWindow_OffscreenPtr);    // <2.10>
  548.     }
  549.     return nil;
  550. }
  551.  
  552. /*
  553.   ##############################################################################
  554.   # Prototype:    PixMapHandle Lock_Offscreen(Window_OffscreenPtr pWindow_OffscreenPtr)
  555.   #=============================================================================
  556.   # Author:            GeoWar    Wednesday,May 24,1995
  557.   # Description:    Locks _Offscreen PixMap & returns its handle.
  558.   # Parameters:        pWindow_OffscreenPtr - Pointer to _Offscreen parameters
  559.   # Returns:        PixMapHandle
  560.   # Examples:        myPixMapHandle = Lock_Offscreen(myWindow_OffscreenPtr);
  561.   # Assumptions:    None
  562.   # ****************************************************************************
  563.   #            C h a n g e        H i s t o r y (most recent first):
  564.   # ****************************************************************************
  565.   #        Vers      Date        Author        Description
  566.   #        ----    --------    ------    ------------------------------------------
  567.   #        2.5         9/25/98    GAW        Added parameter validity checking
  568.   #        2.3         9/25/98    GAW        Added Use count pixel locking/unlocking
  569.   #        0.0         5/24/95    GAW        Initial version
  570.   # ****************************************************************************
  571. */
  572. PixMapHandle Lock_Offscreen(Window_OffscreenPtr pWindow_OffscreenPtr)
  573. {
  574.     if (pWindow_OffscreenPtr)
  575.     {
  576.         PixMapHandle offScreenPixMapH = GetGWorldPixMap(
  577.             pWindow_OffscreenPtr->offscreenWorld);
  578.         if (!pWindow_OffscreenPtr->pixelslockedCount)    // if unlocked...
  579.         {
  580.             if (!LockPixels(offScreenPixMapH))    // if we can't lock...
  581.                 return nil;
  582.         }
  583.         pWindow_OffscreenPtr->pixelslockedCount++;    // bump pixel lock use count
  584.         return offScreenPixMapH;
  585.     }
  586.     else
  587.         return nil;
  588. }
  589.  
  590. /*
  591.   ##############################################################################
  592.   # Prototype:    void Unlock_Offscreen(Window_OffscreenPtr pWindow_OffscreenPtr)
  593.   #=============================================================================
  594.   # Author:            GeoWar    Wednesday,May 24,1995
  595.   # Description:    unlocks _Offscreen pixmap handle
  596.   # Parameters:        pWindow_OffscreenPtr - Pointer to _Offscreen parameters
  597.   # Returns:        none
  598.   # Examples:        Unlock_Offscreen(myWindow_OffscreenPtr);
  599.   # Assumptions:    None
  600.   # ****************************************************************************
  601.   #            C h a n g e        H i s t o r y (most recent first):
  602.   # ****************************************************************************
  603.   #        Vers      Date        Author        Description
  604.   #        ----    --------    ------    ------------------------------------------
  605.   #        2.5         9/25/98    GAW        Added parameter validity checking
  606.   #        2.3         9/25/98    GAW        Added Use count pixel locking/unlocking
  607.   #        0.0         5/24/95    GAW        Initial version
  608.   # ****************************************************************************
  609. */
  610. void Unlock_Offscreen(Window_OffscreenPtr pWindow_OffscreenPtr)
  611. {
  612.     if (pWindow_OffscreenPtr)
  613.     {
  614.         if (pWindow_OffscreenPtr->pixelslockedCount)    // if locked...
  615.         {
  616.             pWindow_OffscreenPtr->pixelslockedCount--;    // bump pixel lock use count
  617.  
  618.             if (!pWindow_OffscreenPtr->pixelslockedCount)    // if lock count zero...
  619.                 UnlockPixels(GetGWorldPixMap(pWindow_OffscreenPtr->offscreenWorld));
  620.         }
  621.     }
  622. }
  623.  
  624. /*
  625.   ##############################################################################
  626.   # Prototype:    SInt16 Get_DefaultPixelDepth(void)
  627.   # Prototype:    SInt16 Set_DefaultPixelDepth(SInt16 pDefaultPixelDepth)
  628.   #=============================================================================
  629.   # Author:            GeoWar    Monday, Nov 4, 1996
  630.   # Description:    accessors for DefaultPixelDepth
  631.   # Parameters:        none & SInt16 pixel depth
  632.   # Returns:        SInt16 pixel depth & previous depth
  633.   # Examples:        x = Get_DefaultPixelDepth(); Set_DefaultPixelDepth(8);
  634.   # Assumptions:    None
  635.   # ****************************************************************************
  636.   #            C h a n g e        H i s t o r y (most recent first):
  637.   # ****************************************************************************
  638.   #        Vers      Date        Author        Description
  639.   #        ----    --------    ------    ------------------------------------------
  640.   #        2.2         9/19/97    GAW        Initial version
  641.   # ****************************************************************************
  642. */
  643. SInt16 Get_DefaultPixelDepth(void)
  644. {
  645.     return gDefaultPixelDepth;
  646. }
  647.  
  648.  
  649. SInt16 Set_DefaultPixelDepth(SInt16 pDefaultPixelDepth)
  650. {
  651.     SInt16 result = gDefaultPixelDepth;
  652.     gDefaultPixelDepth = pDefaultPixelDepth;
  653.     return result;
  654. }
  655.  
  656. /*
  657.   ##############################################################################
  658.   # Prototype:    SInt16 Get_PixelDepth(Window_OffscreenPtr pWindow_OffscreenPtr)
  659.   # Prototype:    SInt16 Set_PixelDepth(
  660.   #                    Window_OffscreenPtr pWindow_OffscreenPtr,SInt16 pPixelDepth)
  661.   #=============================================================================
  662.   # Author:            GeoWar    Monday, Nov 4, 1996
  663.   # Description:    accessors for PixelDepth
  664.   # Parameters:        none & SInt16 pixel depth
  665.   # Returns:        SInt16 pixel depth & previous depth
  666.   # Examples:        x = Get_PixelDepth(myWindow_OffscreenPtr);
  667.   #                    Set_PixelDepth(myWindow_OffscreenPtr,8);
  668.   # Assumptions:    None
  669.   # ****************************************************************************
  670.   #            C h a n g e        H i s t o r y (most recent first):
  671.   # ****************************************************************************
  672.   #        Vers      Date        Author        Description
  673.   #        ----    --------    ------    ------------------------------------------
  674.   #        2.8         12/16/98    GAW        Initial version
  675.   # ****************************************************************************
  676. */
  677. SInt16 Get_PixelDepth(Window_OffscreenPtr pWindow_OffscreenPtr)
  678. {
  679.     return pWindow_OffscreenPtr->pixelDepth;
  680. }
  681.  
  682.  
  683. SInt16 Set_PixelDepth(Window_OffscreenPtr pWindow_OffscreenPtr,SInt16 pPixelDepth)
  684. {
  685.     SInt16 result = pWindow_OffscreenPtr->pixelDepth;
  686.     pWindow_OffscreenPtr->pixelDepth = pPixelDepth;
  687.     return result;
  688. }
  689.  
  690. /*
  691.   ##############################################################################
  692.   # Prototype:    RgnHandle Get_MaskRegion(Window_OffscreenPtr pWindow_OffscreenPtr)
  693.   # Prototype:    RgnHandle Set_MaskRegion(
  694.   #                    Window_OffscreenPtr pWindow_OffscreenPtr,
  695.   #                    RgnHandle pDefaultMaskRegion)
  696.   #=============================================================================
  697.   # Author:            GeoWar    Monday, Nov 4, 1996
  698.   # Description:    accessors for gDefaultMaskRegion
  699.   # Parameters:        none & default mask (RgnHandle)
  700.   # Returns:        RgnHandle mask & previous mask
  701.   # Examples:        myRgn = Get_MaskRegion(myWindow_OffscreenPtr);
  702.   #                            Set_MaskRegion(myWindow_OffscreenPtr,myRgn);
  703.   # Assumptions:    None
  704.   # ****************************************************************************
  705.   #            C h a n g e        H i s t o r y (most recent first):
  706.   # ****************************************************************************
  707.   #        Vers      Date        Author        Description
  708.   #        ----    --------    ------    ------------------------------------------
  709.   #        2.7         12/16/98    GAW        Initial version
  710.   # ****************************************************************************
  711. */
  712. RgnHandle Get_MaskRegion(Window_OffscreenPtr pWindow_OffscreenPtr)
  713. {
  714.     return pWindow_OffscreenPtr->maskRgnHdl;
  715. }
  716.  
  717. RgnHandle Set_MaskRegion(
  718.     Window_OffscreenPtr pWindow_OffscreenPtr,RgnHandle pNewMaskRegion)
  719. {
  720.     RgnHandle result = pWindow_OffscreenPtr->maskRgnHdl;
  721.     pWindow_OffscreenPtr->maskRgnHdl = pNewMaskRegion;
  722.     return result;
  723. }
  724.  
  725. /*
  726.   ##############################################################################
  727.   # Prototype:    void Set_OnscreenWindow(
  728.   #                    Window_OffscreenPtr pWindow_OffscreenPtr,
  729.   #                    WindowPtr pWindowPtr)
  730.   #=============================================================================
  731.   # Author:            GeoWar    Monday, Nov 4, 1996
  732.   # Description:    change the onscreen windowPort & device
  733.   # Parameters:        the WindowPtr
  734.   # Returns:        none
  735.   # Examples:        Set_OnscreenWindow(myWindow_OffscreenPtr,FrontWindow());
  736.   # Assumptions:    None
  737.   # ****************************************************************************
  738.   #            C h a n g e        H i s t o r y (most recent first):
  739.   # ****************************************************************************
  740.   #        Vers      Date        Author        Description
  741.   #        ----    --------    ------    ------------------------------------------
  742.   #        2.14     5/03/00    GAW        Carbonized!
  743.   #        2.7         12/16/98    GAW        Initial version
  744.   # ****************************************************************************
  745. */
  746.  
  747. void Set_OnscreenWindow(Window_OffscreenPtr pWindow_OffscreenPtr,WindowPtr pWindowPtr)
  748. {
  749.     GrafPtr savePort;
  750.  
  751.     GetPort(&savePort);
  752. #if TARGET_API_MAC_CARBON    // <2.14>
  753.     SetPortWindowPort(pWindowPtr);
  754. #else
  755.     SetPort((GrafPtr) pWindowPtr);
  756. #endif TARGET_API_MAC_CARBON
  757.  
  758.     GetGWorld(&pWindow_OffscreenPtr->windowPort, &pWindow_OffscreenPtr->windowDevice);
  759.     SetPort(savePort);
  760. }
  761.  
  762.  
  763. /*
  764.   ##############################################################################
  765.   # Prototype:    GWorldFlags Get_DefaultGWorldFlags(void)
  766.   # Prototype:    GWorldFlags Set_DefaultGWorldFlags(GWorldFlags pDefaultGWorldFlags)
  767.   #=============================================================================
  768.   # Author:            GeoWar    Monday, Nov 4, 1996
  769.   # Description:    accessors for DefaultGWorldFlags
  770.   # Parameters:        none & SInt16 pixel depth
  771.   # Returns:        SInt16 pixel depth & previous depth
  772.   # Examples:        x = Get_DefaultGWorldFlags(); Set_DefaultGWorldFlags(xxx);
  773.   # Assumptions:    None
  774.   # ****************************************************************************
  775.   #            C h a n g e        H i s t o r y (most recent first):
  776.   # ****************************************************************************
  777.   #        Vers      Date        Author        Description
  778.   #        ----    --------    ------    ------------------------------------------
  779.   #        2.12    12/15/99    GAW        Added Get/Set default NewGWorld flags
  780.   # ****************************************************************************
  781. */
  782. GWorldFlags Get_DefaultGWorldFlags(void)
  783. {
  784.     return gDefaultGWorldFlags;
  785. }
  786.  
  787.  
  788. GWorldFlags Set_DefaultGWorldFlags(GWorldFlags pDefaultGWorldFlags)
  789. {
  790.     SInt16 result = gDefaultGWorldFlags;
  791.     gDefaultGWorldFlags = pDefaultGWorldFlags;
  792.     return result;
  793. }
  794.